// pages/operationRecord/operationRecord.js
var app = getApp();
var page_s = 1;
var pageSize = 20;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    record_data: [],
    water_id:'',
    has_more: false, //数据是否加载完成
    load_ing: false, //加载动画
    is_load: false, //是否加载
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      water_id: options.water_id
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    page_s = 1;
    that.setData({
      record_data: []
    })
    this.operationList(page_s);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    // 当没有数据时,不再请求
    var h_more = that.data.has_more;
    if (!h_more) {
      return false;
    }
    that.setData({
      load_ing: true
    })
    page_s += 1;
    this.operationList(page_s);
  },
  //获取操作记录列表
  operationList(page_s){
    var that = this;
    app.ajax({
      url: 'Partner/WaterCard/card_operation_mobile',
      method: "POST",
      data: {
        page: page_s,
        row: pageSize,
        water_id: that.data.water_id,
        type:'',
        start_time:'',
        end_time:''
      },
      success: function (res) {
        // var getData = res.data.data.data[0].child;
        var getData = res.data.data.data;
        var tNum = 0;
        for (var i in getData) {
          tNum = tNum + getData[i].child.length;
          // console.log('结果>>>>>>>>', tNum)
        }
        console.log('数据', getData);
        var h_more = true;
        if (tNum < pageSize) {
          h_more = false;
        }
        that.setData({
          has_more: h_more,
          load_ing: false
        })
        if (res.data.code == 1000) {
          var changeList = [];
          if (that.data.record_data == "") {
            changeList = res.data.data.data;
          } else {
            var addList = that.data.record_data;
            changeList = addList.concat(res.data.data.data);
          }
          that.setData({
            record_data: changeList,
          })
        }
        wx.hideLoading();
        that.setData({
          is_load: true
        })
      }
    })
  }
  
})